package com.kust.smarhome.background.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.query.MPJQueryWrapper;
import com.kust.smarhome.background.common.dto.EvaluateDto;
import com.kust.smarhome.background.mapper.EvaluateMapper;
import com.kust.smarhome.background.model.Evaluate;
import com.kust.smarhome.background.service.IEvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author iAuzre
 * @since 2021-07-31
 */
@Service
public class EvaluateServiceImpl extends ServiceImpl<EvaluateMapper, Evaluate> implements IEvaluateService {

    @Autowired
    private EvaluateMapper evaluateMapper;

    @Override
    public Page<EvaluateDto> getEvaluateInfo(Page page, String orderFormId) {

        /*id orderFormId username commodityName info created state*/
        IPage<EvaluateDto> dtoPage = evaluateMapper.selectJoinPage(page, EvaluateDto.class,
                new MPJQueryWrapper<Evaluate>()
                        .select("t.id", "t.order_form_id as orderFormId", "t.info", "t.created", "t.state")
                        .select("u.username")
                        .leftJoin("user u on t.user_id = u.id")
                        .like(StrUtil.isNotBlank(orderFormId), "orderFormId", orderFormId)
        );

        return (Page<EvaluateDto>) dtoPage;
    }
}
